<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户昵称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入用户昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系方式" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户类型" prop="userType">
        <el-select v-model="queryParams.userType" clearable filterable  placeholder="请选择用户类型">
          <el-option
            v-for="item in dict.type.withdraw_user_type"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" clearable filterable  placeholder="请选择状态">
          <el-option
            v-for="item in dict.type.commis_record_status"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="用户昵称" align="center" prop="nickName" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="用户类型" align="center" prop="userType" >
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.withdraw_user_type" :value="row.userType"/>
        </template>
      </el-table-column>
      <el-table-column label="金额" align="center" prop="price" />
      <el-table-column label="当前总佣金" align="center" prop="totalPrice" />
      <el-table-column label="状态" align="center" prop="status" >
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.commis_record_status" :value="row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150px">
        <template slot-scope="{row}">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(row)"
            v-hasPermi="['trade:brokerageRecord:query']"
          >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row class="diy-text-sm diy-leading-10" :gutter="10" v-if="title == '查看详情'">
          <el-col :span="item.span || 12" v-for="(item,index) in formDetail" :key="index">
            <div class="flex_hcneter">
              <svg-icon icon-class="dot" class-name='diy-text-primary diy-mr-1'/>
              <div v-if="item.zidian && item.isCustom" class="flex_hcneter">
                {{item.label}}：<dict-tag :options="dict.type[item.zidian]" :value="form[item.prop]"/>
              </div>
              <div v-else-if="item.prop == 'description' && item.isCustom">
                {{item.label}}：
                <div v-html="form[item.prop]"></div>
              </div>
              <div v-else>{{item.label}}：{{ form[item.prop] }}{{ item.danwei || '' }}</div>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBrokerageRecord, getBrokerageRecord, } from "@/api/finance/commisRecord";
export default {
  name: "CommisRecord",
  dicts: ['withdraw_user_type','commis_record_status',],
  components: { },
  data() {
    return {
      formDetail:[//表单
        {label:'用户昵称',prop:'nickName',},{label:'手机号',prop:'phone',},
        {label:'用户类型',prop:'userType',zidian:'withdraw_user_type',isCustom:true,}, {label:'标题',prop:'title',},
        {label:'金额',prop:'price',},{label:'当前总佣金',prop:'totalPrice',},
        {label:'说明',prop:'description',isCustom:true,span:24,},{label:'状态',prop:'status',zidian:'commis_record_status',isCustom:true,},
        {label:'冻结时间（天）',prop:'frozenDays',},{label:'解冻时间',prop:'unfreezeTime',},{label:'创建时间',prop:'createTime',},
      ],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,phone: undefined,nickName: undefined,
        userType: undefined,status: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    urlLink(row){//链接跳转
      window.open(row)
    },
    /** 查列表 */
    getList() {
      this.loading = true;
      listBrokerageRecord(this.queryParams).then(response => {
        let rows = response.rows || [];
        this.list = rows.map(item=>{
          return {
            ...item,
            price:this.math.divide(item.price || 0,100),
            totalPrice:this.math.divide(item.totalPrice || 0,100),
          }
        })
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleDetail(row) {
      const id = row.id
      getBrokerageRecord(id).then(response => {
        let data =  response.data || {};
        this.form = {
          ...data,
          price:this.math.divide(data.price || 0,100),
          totalPrice:this.math.divide(data.totalPrice || 0,100),
        }
        this.open = true;
        this.title = "查看详情";
      });
    },
  }
};
</script>